package com.yeswater.algorithm.leetcode.hot100;

public class Code647 {

    public static void main(String[] args) {
        String s = "aaa";
        Code647 code647 = new Code647();
        System.out.println(code647.countSubstrings(s));
    }

    public int countSubstrings(String s) {
        int count = s.length();
        for(int i=0; i<s.length(); i++){
            int l = i-1;
            int r = i+1;
            // 往两边扩散
            while (l>=0 && r<s.length() && s.charAt(l) == s.charAt(r)){
                l--;
                r++;
                count++;
            }

            l = i;
            r = i+1;
            // 往两边扩散
            while (l>=0 && r<s.length() && s.charAt(l) == s.charAt(r)){
                l--;
                r++;
                count++;
            }
        }
        return count;
    }

}
